﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data.Models.Center;
using ZHDJ.WebPage;

namespace ZHDJ.Web.Portal.MeetingLecture
{
    public partial class MeetingCalendar : PortalPage
    {
        public string BranchID
        {
            get
            {
                return this.Request["BranchID"] ?? "";
            }
        }

        public string Month
        {
            get
            {
                return this.Request["Month"] ?? "";
            }
        }

        public string Year
        {
            get
            {
                return this.Request["Year"] ?? DateTime.Now.Year.ToString();
            }
        }

        public string IsPartyAdmin
        {
            get
            {
                return this.Request["IsPartyAdmin"] ?? "";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            CheckLogin(true);

            if (!IsPostBack)
            {
                BindData();
                ddlMonth.SelectedValue = this.Month;
                ddlEndMonth.SelectedValue = "";
                ddlYear.SelectedValue = this.Year;

            }
        }

        protected void BindData()
        {
            ListItem item = new ListItem() { Text = "===未指定===", Value = "" };
            this.ddlYear.Items.Add(item);

            for (int i = 3; i >= 0; i--)
            {
                ListItem year = new ListItem() { Text = (DateTime.Now.Year - i).ToString() + "年", Value = (DateTime.Now.Year - i).ToString() };
                this.ddlYear.Items.Add(year);
            }

            ListItem itemMonth = new ListItem() { Text = "===未指定===", Value = "" };
            this.ddlMonth.Items.Add(itemMonth);
            ListItem itemMonth2 = new ListItem() { Text = "===未指定===", Value = "" };
            this.ddlEndMonth.Items.Add(itemMonth2);
            for (int i = 1; i < 13; i++)
            {
                ListItem month = new ListItem() { Text = ChangeNumber(i.ToString()), Value = i.ToString() };
                
                this.ddlEndMonth.Items.Add(month);
            }
            for (int i = 1; i < 13; i++)
            {
                ListItem month = new ListItem() { Text = ChangeNumber(i.ToString()), Value = i.ToString() };
                this.ddlMonth.Items.Add(month);
               
            }
        }

        public DataTable GetMeetingCalendar(string month)
        {
            string year = DateTime.Now.Year.ToString();
            if (!string.IsNullOrEmpty(ddlYear.SelectedValue))
            {
                year = ddlYear.SelectedValue;
            }
            return PartyMeetingLecture.GetMeetingCalendar(BranchID, year, month, ddlType.SelectedValue);
        }

        public string GetMeetingMember(string id)
        {
            DataTable dt = PartyMeetingLectureMember.GetGridData(id, "1");
            List<string> list = new List<string>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow item in dt.Rows)
                {
                    list.Add(Convert.ToString(item["UserName"]));
                }

                return string.Join(",", list);
            }
            else
            {
                return "";
            }
        }

        public string ChangeNumber(string number)
        {
            switch (number)
            {
                case "1": return "一月";
                case "2": return "二月";
                case "3": return "三月";
                case "4": return "四月";
                case "5": return "五月";
                case "6": return "六月";
                case "7": return "七月";
                case "8": return "八月";
                case "9": return "九月";
                case "10": return "十月";
                case "11": return "十一月";
                case "12": return "十二月";
                default: return "";
            }
        }
    }
}